package com.huibao.hulibao.adapter;

import android.content.Context;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huibao.hulibao.R;
import com.huibao.hulibao.constant.GlobalConstants;
import com.huibao.hulibao.entity.HuLiLogEntity;
import com.huibao.hulibao.entity.ScanEntity;
import com.huibao.hulibao.utils.MyUtils;
import com.nex3z.flowlayout.FlowLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lizhaoyong on 2018/5/7.
 */
public class ScanLvAdapter extends BaseAdapter {
    private ArrayList<ScanEntity> mDatas;
    private Context mContext;


    private LayoutInflater mInflater;


    public ScanLvAdapter(ArrayList<ScanEntity> datas, Context context) {
        this.mDatas = datas;
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        ScanEntity se = mDatas.get(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_lv_scan, parent, false);
            holder = new ViewHolder(convertView);
            // holder.mTextView = (TextView)convertView.findViewById(R.id.tv_title);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tv_label.setText(se.getScanLabel().split(":")[0]);
        if (se.isScan()) {
            // holder.iv_ok.setBackground(mContext.getResources().getDrawable(R.drawable.shape_badge_green));
            holder.iv_ok.setBackgroundResource(R.mipmap.scan_pass);
        } else {
            // holder.iv_ok.setBackground(mContext.getResources().getDrawable(R.drawable.shape_badge));
            holder.iv_ok.setBackgroundResource(R.mipmap.scan_no_pass);
        }

        return convertView;
    }


    static class ViewHolder {

        @BindView(R.id.tv_label)
        TextView tv_label;
        @BindView(R.id.iv_ok)
        ImageView iv_ok;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
